﻿<ResourceDictionary
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:Local="clr-namespace:EnumEditor"
    xmlns:Converters="clr-namespace:EnumEditor.Converters">

    <Style TargetType="{x:Type Local:EnumEditor}">
        <Setter Property="Template">
            <Setter.Value>
                <ControlTemplate TargetType="{x:Type Local:EnumEditor}">
                    <ControlTemplate.Resources>
                        <DataTemplate x:Key="EnumValue">
                            <ComboBox SelectedItem="{Binding Value, Mode=TwoWay}" ItemsSource="{Binding Items}"/>
                        </DataTemplate>

                        <DataTemplate x:Key="EnumValueReadOnly">
                            <TextBlock Text="{Binding Value}"/>
                        </DataTemplate>

                        <DataTemplate x:Key="FlagsValue">
                            <Expander IsExpanded="False" ExpandDirection="Down" Header="{Binding Value, Converter={x:Static Converters:List.ToString}, UpdateSourceTrigger=PropertyChanged}">
                                <ItemsControl ItemsSource="{Binding Items}">
                                    <ItemsControl.ItemsPanel>
                                        <ItemsPanelTemplate>
                                            <StackPanel Orientation="Vertical"/>
                                        </ItemsPanelTemplate>
                                    </ItemsControl.ItemsPanel>
                                    <ItemsControl.ItemTemplate>
                                        <DataTemplate>
                                            <CheckBox IsChecked="{Binding IsChecked, Mode=TwoWay}">
                                                <TextBlock Text="{Binding}"/>
                                            </CheckBox>
                                        </DataTemplate>
                                    </ItemsControl.ItemTemplate>
                                    <ItemsControl.Template>
                                        <ControlTemplate>
                                            <ScrollViewer VerticalScrollBarVisibility="Auto">
                                                <ItemsPresenter/>
                                            </ScrollViewer>
                                        </ControlTemplate>
                                    </ItemsControl.Template>
                                </ItemsControl>
                            </Expander>
                        </DataTemplate>

                        <DataTemplate x:Key="FlagsValueReadOnly">
                            <ItemsControl ItemsSource="{Binding Value}">
                                <ItemsControl.ItemsPanel>
                                    <ItemsPanelTemplate>
                                        <StackPanel Orientation="Vertical"/>
                                    </ItemsPanelTemplate>
                                </ItemsControl.ItemsPanel>
                                <ItemsControl.ItemTemplate>
                                    <DataTemplate>
                                        <TextBlock Text="{Binding}"/>
                                    </DataTemplate>
                                </ItemsControl.ItemTemplate>
                                <ItemsControl.Template>
                                    <ControlTemplate>
                                        <ScrollViewer VerticalScrollBarVisibility="Auto">
                                            <ItemsPresenter/>
                                        </ScrollViewer>
                                    </ControlTemplate>
                                </ItemsControl.Template>
                            </ItemsControl>
                        </DataTemplate>
                    </ControlTemplate.Resources>

                    <ContentControl Content="{Binding EditValue, RelativeSource={RelativeSource TemplatedParent}}" ContentTemplateSelector="{Binding TemplateSelector, RelativeSource={RelativeSource TemplatedParent}}" x:Name="EnumControl"/>

                </ControlTemplate>
            </Setter.Value>
        </Setter>
    </Style>
</ResourceDictionary>
